import { CouponQuery, CouponPageResult, CouponForm } from "./types";
import request from "@/utils/request";
import { AxiosPromise } from "axios";

/* 获取优惠券分页列表 */
export function lisCouponPages(
  queryParams: CouponQuery
): AxiosPromise<CouponPageResult> {
  return request({
    url: "/mall-sms/api/v1/coupons/pages",
    method: "get",
    params: queryParams,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 获取优惠券表单数据 */
export function getCouponForm(id: number): AxiosPromise<CouponForm> {
  return request({
    url: "/mall-sms/api/v1/coupons/" + id + "/form_data",
    method: "get",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 添加优惠券 */
export function addCoupon(data: CouponForm) {
  return request({
    url: "/mall-sms/api/v1/coupons",
    method: "post",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 修改优惠券 */
export function updateCoupon(id: number, data: CouponForm) {
  return request({
    url: "/mall-sms/api/v1/coupons/" + id,
    method: "put",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 删除优惠券 */
export function deleteCoupons(id: string) {
  return request({
    url: "/mall-sms/api/v1/coupons/" + id,
    method: "delete",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}
